//2010-4-29 anthony wang

//最高层
var max_layer = "${fld:max_layer}";
//alert(max_layer);

//共几个单元
var total_unit = 0;

//一层所含的最多单元数目
var total_unitSmall = 0;

var intLoop=0;



//单元数组，记录单元号
var arrUnit = new Array();

//记录单元对应的小单元个数
var arrUnitSmall = new Array();
<rows2>
total_unitSmall = total_unitSmall + parseInt("${fld:unit_no_small}");
total_unit++;

arrUnit[intLoop] = "${fld:unit_no}";
arrUnitSmall[intLoop] = "${fld:unit_no_small}";
intLoop++;
</rows2>

//alert("arrUnitSmall[2]:"+arrUnitSmall[2]);


//alert("最高层：  "+max_layer+"\n 最多单元:"+total_unitSmall+": \n www");

var formObj = document.formEditor;
var whereObj = -1;
//clearBGColors();
var newCell;

for (var i = (max_layer-1); i >=0 ; i--)
{
var newRow = theTableBody.insertRow(whereObj);
    for (var j = 0; j < total_unitSmall; j++) {
        newCell = newRow.insertCell(j);
        newCell.innerHTML = "<br><br><br><br>";
        newCell.id = "td"+i+"-"+j;
        newCell.style.backgroundColor = "#ffffff";
    }
}
updateRowCounters(formObj);

//往table上打印数据
var intX = 0;
var intY = 0;

var tempStr ="";

<rows1>
//确定横坐标
var layer_no = "${fld:layer_no}";
intX = parseInt(layer_no)-1;

//确定纵坐标
var unitNo = "${fld:unit_no}";
//数据位于单元的index位置(即第几单元)？
//alert("total_unit:"+total_unit);
var unitNoIndex = 0;
for (var intZ = 0; intZ < total_unit; intZ++) {
    if (arrUnit[intZ] == unitNo) {
        unitNoIndex = intZ;
    }
}
// 该单元前面所有单元的小单元数目
var intUnitNoSmallPre = 0;
if (unitNoIndex > 0) {
    for (var intZ = 0; intZ < unitNoIndex; intZ++) {
        intUnitNoSmallPre = intUnitNoSmallPre + parseInt(arrUnitSmall[intZ]);
        
    }
}
//房间在本单元所处的位置(及第几小单元)
var mark_no = "${fld:mark_no}";
var max_layer_no = "${fld:max_layer_no}";
var lenthMaxLayerNo = max_layer_no.length;
//alert(lenthMaxLayerNo);
var unitNoSmallIndex = Math.abs(parseInt(mark_no.substring(mark_no.length-lenthMaxLayerNo)));

//纵坐标
intY = intUnitNoSmallPre + unitNoSmallIndex - 1;

var tdObj = "td"+ (intX + "") +"-"+ (intY + "");


if(document.getElementById(tdObj)){
    var houseContent="";

    //根据楼源状态设置平面图的背景颜色
    //0:初始状态;1:可分配;2:待抓阄;3:已分配;4:已结算;5:已归档;8:暂保留;9:不可分配;未知状态
    var backColor = "";
    var houseStatus = "${fld:house_status}"; 
    if(houseStatus == "0") {backColor = "";}
    else if(houseStatus == "1") {backColor = "#3F0";}
    else if(houseStatus == "2") {backColor = "";}
    else if(houseStatus == "3") {backColor = "#F00";}
    else if(houseStatus == "4") {backColor = "#00F";}
    else if(houseStatus == "5") {backColor = "";}
    else if(houseStatus == "6") {backColor = "#FF0";}
    else if(houseStatus == "7") {backColor = "";}
    else if(houseStatus == "8") {backColor = "";}
    else if(houseStatus == "9") {backColor = "";}
    
    houseContent = houseContent + "<table><tr><td style='background-color:"+backColor+"' nowrap>";
    houseContent = houseContent + "${fld:house_name}";

    var is_top_layer = "${fld:is_top_layer}";
    if (is_top_layer=="1")
    {
        houseContent = houseContent + "<font color='green'>(顶层)</font>";
    }
    houseContent = houseContent + "</td></tr><td nowrap>";

    houseContent = houseContent + "建筑面积:${fld:jianzhu_area}";
    houseContent = houseContent + "<br> 结算面积:${fld:jiesuan_area}";
    houseContent = houseContent + "<br>状态:${fld:house_status_alias}";
	houseContent = houseContent + "<br>姓名:${fld:master_name}";

	if("${fld:house_status}" == "1"){//待分配
		houseContent = houseContent + "<br> <a href='javascript:pickUpdateStatus(\"s${fld:tuid}\",${fld:tuid})' id='s${fld:tuid}'>更改状态</a>";
		houseContent = houseContent + "<br> <a href='javascript:pickAddMaster(\"a${fld:tuid}\",${fld:tuid})' id='a${fld:tuid}'>新增房主</a>";
	}else if("${fld:house_status}" == "3"){//已分配
		houseContent = houseContent + "<br> <a href='javascript:pickCancelMaster(\"c${fld:tuid}\",${fld:tuid})' id='c${fld:tuid}'>取消房主</a>";
		houseContent += "<br> <a href='javascript:updateSheshiPrice(${fld:master_tuid})'>房屋设施</a>";
	}else if("${fld:house_status}" == "4" || "${fld:house_status}" == "6"){//已结算，结算已审核
		houseContent = houseContent + "<br> <a href='javascript:pickCancelMaster(\"c${fld:tuid}\",${fld:tuid})' id='c${fld:tuid}'>取消房主</a>";
	}else if("${fld:house_status}" == "8"){//暂保留
		houseContent = houseContent + "<br> <a href='javascript:pickUpdateStatus(\"s${fld:tuid}\",${fld:tuid})' id='s${fld:tuid}'>更改状态</a>";
	}else if("${fld:house_status}" == "9"){//不可分配
		houseContent = houseContent + "<br> <a href='javascript:pickUpdateStatus(\"s${fld:tuid}\",${fld:tuid})' id='s${fld:tuid}'>更改状态</a>";
	}
	
	if("${fld:master_name}"!="" && "${fld:house_status}" != "5"){
        houseContent = houseContent + "<br> <a href='javascript:masterJiesuan(${fld:tuid})'>【结算】</a>";
    }

    houseContent = houseContent + "</td></tr></table>";
    document.getElementById(tdObj).innerHTML=houseContent;
    //打印小区名称
    var newCaption = theTable.createCaption();
    newCaption.innerHTML = "${fld:location_name1}-${fld:serial_no}号楼";
}
</rows1>
